package com.studentmanagement.controller;

import com.our.learning.infrastructure.po.Clazz;
import com.our.learning.infrastructure.pojo.Response;
import com.studentmanagement.service.ClassService;
import org.springframework.web.bind.annotation.*;

/**
 * 接受和处理有关班级的请求
 *
 * @author hexujie
 * @date 2023-06-20 23:10
 */
@RestController
@RequestMapping("/class")
public class ClassController {
    private final ClassService classService;

    public ClassController(ClassService classService) {
        this.classService = classService;
    }

    @PostMapping
    public Response createClass(@RequestBody Clazz clazz) {
        return classService.createClass(clazz);
    }

    @PatchMapping("/modify")
    public Response updateClass(@RequestBody Clazz clazz) {
        return classService.modifyClass(clazz);
    }


    @PostMapping("/addStudent")
    public Response addStudentToClass(Integer classId, Integer stuId) {
        return classService.addStudentToClass(stuId, classId);
    }

    @PostMapping("/removeStudent")
    public Response removeStudentFromClass(Integer stuId, Integer classId) {
        return classService.removeStudentFromClass(stuId, classId);
    }

    @GetMapping("/list")
    public Response classList(Integer classId) {
        return classService.classList(classId);
    }
}
